package com.stone.bean;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
public class AppResponse<T> {
    public static final int code_error_login = 601;
    public static final int code_error_server = 602;
    public static final int code_error_no_permission = 603;
    public static final int code_error_need_verify = 604;
    public static final int code_error_business = 605;
    public static final int code_error_no_resource = 606;
    public static final int code_error_resource_conflict = 607;
    public static final int code_error_login_failed = 608;
    public static final int code_duplication_submit = 609;
    public static final int code_error = 999;
    public static final int code_intercept = 700;
    public static final int code_success = 200;
    @ApiModelProperty("200代表成功")
    private int code;
    @ApiModelProperty("分页时总数据条数")
    private long total;
    @ApiModelProperty("描述信息")
    private String message;
    @ApiModelProperty("jsonObject")
    private T record;
    @ApiModelProperty("jsonArray")
    private List<T> records;

    private AppResponse() {
    }

    public static AppResponse success() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_success;
        return appResponse;
    }

    public static AppResponse intercept() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_intercept;
        appResponse.setMessage("business intercept");
        return appResponse;
    }

    public static AppResponse failed() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_error;
        appResponse.setMessage("system report error");
        return appResponse;
    }

    public static AppResponse noResource() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_error_no_resource;
        appResponse.setMessage("can not find resource");
        return appResponse;
    }

    public static AppResponse needLogin() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_error_login;
        appResponse.setMessage("please login first");
        return appResponse;
    }

    public static AppResponse noPermission() {
        return failed().setCode(603).setMessage("no permission to complete this task ");
    }

    public static AppResponse conflict() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_error_resource_conflict;
        appResponse.setMessage("resource conflict");
        return appResponse;
    }

    public static AppResponse loginFailed() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_error_login_failed;
        appResponse.setMessage("login failed");
        return appResponse;
    }

    public static AppResponse duplicationSubmit() {
        AppResponse appResponse = new AppResponse();
        appResponse.code = AppResponse.code_duplication_submit;
        appResponse.setMessage("Please do not submit repeatedly");
        return appResponse;
    }

}
